<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link href="cpip.css" rel="stylesheet" type="text/css" />
    <title>File: /Users/paulross/dev/linux/linux-3.13/include/linux/jiffies.h</title>
  </head>
  <body>
    <h1>File: /Users/paulross/dev/linux/linux-3.13/include/linux/jiffies.h</h1>
    <p>Green shading in the line number column
means the source is part of the translation unit, red means it is conditionally excluded.
Highlighted line numbers link to the translation unit page. Highlighted macros link to
the macro page.</p>
    <pre><a name="1" /><span class="Maybe">       1:</span> <span class="f">#</span><span class="n">ifndef</span> <a href="cpu.c_macros_ref.html#_X0xJTlVYX0pJRkZJRVNfSF8w"><span class="b">_LINUX_JIFFIES_H</span></a>
<a name="2" /><span class="Maybe">       2:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_X0xJTlVYX0pJRkZJRVNfSF8w"><span class="b">_LINUX_JIFFIES_H</span></a>
<a name="3" /><span class="Maybe">       3:</span> 
<a name="4" /><span class="Maybe">       4:</span> <span class="f">#</span><span class="n">include</span> <span class="f">&lt;</span><span class="b">linux</span><span class="f">/</span><span class="b">math64</span><span class="f">.</span><span class="b">h</span><span class="f">&gt;</span>
<a name="5" /><span class="Maybe">       5:</span> <span class="f">#</span><span class="n">include</span> <span class="f">&lt;</span><span class="b">linux</span><span class="f">/</span><span class="b">kernel</span><span class="f">.</span><span class="b">h</span><span class="f">&gt;</span>
<a name="6" /><span class="Maybe">       6:</span> <span class="f">#</span><span class="n">include</span> <span class="f">&lt;</span><span class="b">linux</span><span class="f">/</span><span class="b">types</span><span class="f">.</span><span class="b">h</span><span class="f">&gt;</span>
<a name="7" /><span class="Maybe">       7:</span> <span class="f">#</span><span class="n">include</span> <span class="f">&lt;</span><span class="b">linux</span><span class="f">/</span><span class="b">time</span><span class="f">.</span><span class="b">h</span><span class="f">&gt;</span>
<a name="8" /><span class="Maybe">       8:</span> <span class="f">#</span><span class="n">include</span> <span class="f">&lt;</span><span class="b">linux</span><span class="f">/</span><span class="b">timex</span><span class="f">.</span><span class="b">h</span><span class="f">&gt;</span>
<a name="9" /><span class="Maybe">       9:</span> <span class="f">#</span><span class="n">include</span> <span class="f">&lt;</span><span class="m">asm</span><span class="f">/</span><span class="b">param</span><span class="f">.</span><span class="b">h</span><span class="f">&gt;</span>            <span class="k">/* for HZ */</span>
<a name="10" /><span class="Maybe">      10:</span> 
<a name="11" /><span class="Maybe">      11:</span> <span class="k">/*</span>
<a name="12" /><span class="Maybe">      12:</span> <span class="k"> * The following defines establish the engineering parameters of the PLL</span>
<a name="13" /><span class="Maybe">      13:</span> <span class="k"> * model. The HZ variable establishes the timer interrupt frequency, 100 Hz</span>
<a name="14" /><span class="Maybe">      14:</span> <span class="k"> * for the SunOS kernel, 256 Hz for the Ultrix kernel and 1024 Hz for the</span>
<a name="15" /><span class="Maybe">      15:</span> <span class="k"> * OSF/1 kernel. The SHIFT_HZ define expresses the same value as the</span>
<a name="16" /><span class="Maybe">      16:</span> <span class="k"> * nearest power of two in order to avoid hardware multiply operations.</span>
<a name="17" /><span class="Maybe">      17:</span> <span class="k"> */</span>
<a name="18" /><span class="False">      18:</span> <span class="f">#</span><span class="n">if</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&gt;=</span> <span class="c">12</span> <span class="f">&amp;&amp;</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&lt;</span> <span class="c">24</span>
<a name="19" /><span class="False">      19:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a>    <span class="c">4</span>
<a name="20" /><span class="False">      20:</span> <span class="f">#</span><span class="n">elif</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&gt;=</span> <span class="c">24</span> <span class="f">&amp;&amp;</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&lt;</span> <span class="c">48</span>
<a name="21" /><span class="False">      21:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a>    <span class="c">5</span>
<a name="22" /><span class="False">      22:</span> <span class="f">#</span><span class="n">elif</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&gt;=</span> <span class="c">48</span> <span class="f">&amp;&amp;</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&lt;</span> <span class="c">96</span>
<a name="23" /><span class="False">      23:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a>    <span class="c">6</span>
<a name="24" /><span class="Maybe">      24:</span> <span class="f">#</span><span class="n">elif</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&gt;=</span> <span class="c">96</span> <span class="f">&amp;&amp;</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&lt;</span> <span class="c">192</span>
<a name="25" /><span class="Maybe">      25:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a>    <span class="c">7</span>
<a name="26" /><span class="False">      26:</span> <span class="f">#</span><span class="n">elif</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&gt;=</span> <span class="c">192</span> <span class="f">&amp;&amp;</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&lt;</span> <span class="c">384</span>
<a name="27" /><span class="False">      27:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a>    <span class="c">8</span>
<a name="28" /><span class="False">      28:</span> <span class="f">#</span><span class="n">elif</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&gt;=</span> <span class="c">384</span> <span class="f">&amp;&amp;</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&lt;</span> <span class="c">768</span>
<a name="29" /><span class="False">      29:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a>    <span class="c">9</span>
<a name="30" /><span class="False">      30:</span> <span class="f">#</span><span class="n">elif</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&gt;=</span> <span class="c">768</span> <span class="f">&amp;&amp;</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&lt;</span> <span class="c">1536</span>
<a name="31" /><span class="False">      31:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a>    <span class="c">10</span>
<a name="32" /><span class="False">      32:</span> <span class="f">#</span><span class="n">elif</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&gt;=</span> <span class="c">1536</span> <span class="f">&amp;&amp;</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&lt;</span> <span class="c">3072</span>
<a name="33" /><span class="False">      33:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a>    <span class="c">11</span>
<a name="34" /><span class="False">      34:</span> <span class="f">#</span><span class="n">elif</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&gt;=</span> <span class="c">3072</span> <span class="f">&amp;&amp;</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&lt;</span> <span class="c">6144</span>
<a name="35" /><span class="False">      35:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a>    <span class="c">12</span>
<a name="36" /><span class="False">      36:</span> <span class="f">#</span><span class="n">elif</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&gt;=</span> <span class="c">6144</span> <span class="f">&amp;&amp;</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a> <span class="f">&lt;</span> <span class="c">12288</span>
<a name="37" /><span class="False">      37:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a>    <span class="c">13</span>
<a name="38" /><span class="False">      38:</span> <span class="f">#</span><span class="n">else</span>
<a name="39" /><span class="False">      39:</span> <span class="f">#</span> <span class="n">error</span> <span class="b">Invalid</span> <span class="b">value</span> <span class="b">of</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a><span class="f">.</span>
<a name="40" /><span class="Maybe">      40:</span> <span class="f">#</span><span class="n">endif</span>
<a name="41" /><span class="Maybe">      41:</span> 
<a name="42" /><span class="Maybe">      42:</span> <span class="k">/* Suppose we want to divide two numbers NOM and DEN: NOM/DEN, then we can</span>
<a name="43" /><span class="Maybe">      43:</span> <span class="k"> * improve accuracy by shifting LSH bits, hence calculating:</span>
<a name="44" /><span class="Maybe">      44:</span> <span class="k"> *     (NOM &lt;&lt; LSH) / DEN</span>
<a name="45" /><span class="Maybe">      45:</span> <span class="k"> * This however means trouble for large NOM, because (NOM &lt;&lt; LSH) may no</span>
<a name="46" /><span class="Maybe">      46:</span> <span class="k"> * longer fit in 32 bits. The following way of calculating this gives us</span>
<a name="47" /><span class="Maybe">      47:</span> <span class="k"> * some slack, under the following conditions:</span>
<a name="48" /><span class="Maybe">      48:</span> <span class="k"> *   - (NOM / DEN) fits in (32 - LSH) bits.</span>
<a name="49" /><span class="Maybe">      49:</span> <span class="k"> *   - (NOM % DEN) fits in (32 - LSH) bits.</span>
<a name="50" /><span class="Maybe">      50:</span> <span class="k"> */</span>
<a name="51" /><span class="Maybe">      51:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_U0hfRElWXzA_"><span class="b">SH_DIV</span></a><span class="f">(</span><span class="b">NOM</span><span class="f">,</span><span class="b">DEN</span><span class="f">,</span><span class="b">LSH</span><span class="f">)</span> <span class="f">(</span>   <span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="b">NOM</span><span class="f">)</span> <span class="f">/</span> <span class="f">(</span><span class="b">DEN</span><span class="f">)</span><span class="f">)</span> <span class="f">&lt;&lt;</span> <span class="f">(</span><span class="b">LSH</span><span class="f">)</span><span class="f">)</span>              \
<a name="52" /><span class="Maybe">      52:</span>                              <span class="f">+</span> <span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="b">NOM</span><span class="f">)</span> <span class="f">%</span> <span class="f">(</span><span class="b">DEN</span><span class="f">)</span><span class="f">)</span> <span class="f">&lt;&lt;</span> <span class="f">(</span><span class="b">LSH</span><span class="f">)</span><span class="f">)</span> <span class="f">+</span> <span class="f">(</span><span class="b">DEN</span><span class="f">)</span> <span class="f">/</span> <span class="c">2</span><span class="f">)</span> <span class="f">/</span> <span class="f">(</span><span class="b">DEN</span><span class="f">)</span><span class="f">)</span>
<a name="53" /><span class="Maybe">      53:</span> 
<a name="54" /><span class="Maybe">      54:</span> <span class="k">/* LATCH is used in the interval timer and ftape setup. */</span>
<a name="55" /><span class="Maybe">      55:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_TEFUQ0hfMA__"><span class="b">LATCH</span></a> <span class="f">(</span><span class="f">(</span><a href="cpu.c_macros_noref.html#_Q0xPQ0tfVElDS19SQVRFXzA_"><span class="b">CLOCK_TICK_RATE</span></a> <span class="f">+</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a><span class="f">/</span><span class="c">2</span><span class="f">)</span> <span class="f">/</span> <a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a><span class="f">)</span>    <span class="k">/* For divider */</span>
<a name="56" /><span class="Maybe">      56:</span> 
<a name="57" /><span class="Maybe">      57:</span> <span class="m">extern</span> <span class="m">int</span> <span class="b">register_refined_jiffies</span><span class="f">(</span><span class="m">long</span> <span class="b">clock_tick_rate</span><span class="f">)</span><span class="f">;</span>
<a name="58" /><span class="Maybe">      58:</span> 
<a name="59" /><span class="Maybe">      59:</span> <span class="k">/* TICK_NSEC is the time between ticks in nsec assuming SHIFTED_HZ */</span>
<a name="60" /><span class="Maybe">      60:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_VElDS19OU0VDXzA_"><span class="b">TICK_NSEC</span></a> <span class="f">(</span><span class="f">(</span><a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfU0VDXzA_"><span class="b">NSEC_PER_SEC</span></a><span class="f">+</span><a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a><span class="f">/</span><span class="c">2</span><span class="f">)</span><span class="f">/</span><a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a><span class="f">)</span>
<a name="61" /><span class="Maybe">      61:</span> 
<a name="62" /><span class="Maybe">      62:</span> <span class="k">/* TICK_USEC is the time between ticks in usec assuming fake USER_HZ */</span>
<a name="63" /><span class="Maybe">      63:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_VElDS19VU0VDXzA_"><span class="b">TICK_USEC</span></a> <span class="f">(</span><span class="f">(</span><span class="c">1000000UL</span> <span class="f">+</span> <a href="cpu.c_macros_noref.html#_VVNFUl9IWl8w"><span class="b">USER_HZ</span></a><span class="f">/</span><span class="c">2</span><span class="f">)</span> <span class="f">/</span> <a href="cpu.c_macros_noref.html#_VVNFUl9IWl8w"><span class="b">USER_HZ</span></a><span class="f">)</span>
<a name="64" /><span class="Maybe">      64:</span> 
<a name="65" /><span class="Maybe">      65:</span> <span class="k">/* some arch&apos;s have a small-data section that can be accessed register-relative</span>
<a name="66" /><span class="Maybe">      66:</span> <span class="k"> * but that can only take up to, say, 4-byte variables. jiffies being part of</span>
<a name="67" /><span class="Maybe">      67:</span> <span class="k"> * an 8-byte variable may not be correctly accessed unless we force the issue</span>
<a name="68" /><span class="Maybe">      68:</span> <span class="k"> */</span>
<a name="69" /><span class="Maybe">      69:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_X19qaWZmeV9kYXRhXzA_"><span class="b">__jiffy_data</span></a>  <span class="b">__attribute__</span><span class="f">(</span><span class="f">(</span><span class="b">section</span><span class="f">(</span><span class="e">&quot;.data&quot;</span><span class="f">)</span><span class="f">)</span><span class="f">)</span>
<a name="70" /><span class="Maybe">      70:</span> 
<a name="71" /><span class="Maybe">      71:</span> <span class="k">/*</span>
<a name="72" /><span class="Maybe">      72:</span> <span class="k"> * The 64-bit value is not atomic - you MUST NOT read it</span>
<a name="73" /><span class="Maybe">      73:</span> <span class="k"> * without sampling the sequence number in jiffies_lock.</span>
<a name="74" /><span class="Maybe">      74:</span> <span class="k"> * get_jiffies_64() will do this for you as appropriate.</span>
<a name="75" /><span class="Maybe">      75:</span> <span class="k"> */</span>
<a name="76" /><span class="Maybe">      76:</span> <span class="m">extern</span> <span class="b">u64</span> <a href="cpu.c_macros_ref.html#_X19qaWZmeV9kYXRhXzA_"><span class="b">__jiffy_data</span></a> <span class="b">jiffies_64</span><span class="f">;</span>
<a name="77" /><span class="Maybe">      77:</span> <span class="m">extern</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="m">volatile</span> <a href="cpu.c_macros_ref.html#_X19qaWZmeV9kYXRhXzA_"><span class="b">__jiffy_data</span></a> <span class="b">jiffies</span><span class="f">;</span>
<a name="78" /><span class="Maybe">      78:</span> 
<a name="79" /><span class="False">      79:</span> <span class="f">#</span><span class="n">if</span> <span class="f">(</span><a href="cpu.c_macros_ref.html#_QklUU19QRVJfTE9OR18w"><span class="b">BITS_PER_LONG</span></a> <span class="f">&lt;</span> <span class="c">64</span><span class="f">)</span>
<a name="80" /><span class="False">      80:</span> <span class="b">u64</span> <span class="b">get_jiffies_64</span><span class="f">(</span><span class="m">void</span><span class="f">)</span><span class="f">;</span>
<a name="81" /><span class="Maybe">      81:</span> <span class="f">#</span><span class="n">else</span>
<a name="82" /><span class="Maybe">      82:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">u64</span> <span class="b">get_jiffies_64</span><span class="f">(</span><span class="m">void</span><span class="f">)</span>
<a name="83" /><span class="Maybe">      83:</span> <span class="f">{</span>
<a name="84" /><span class="Maybe">      84:</span>     <span class="m">return</span> <span class="f">(</span><span class="b">u64</span><span class="f">)</span><span class="b">jiffies</span><span class="f">;</span>
<a name="85" /><span class="Maybe">      85:</span> <span class="f">}</span>
<a name="86" /><span class="Maybe">      86:</span> <span class="f">#</span><span class="n">endif</span>
<a name="87" /><span class="Maybe">      87:</span> 
<a name="88" /><span class="Maybe">      88:</span> <span class="k">/*</span>
<a name="89" /><span class="Maybe">      89:</span> <span class="k"> *    These inlines deal with timer wrapping correctly. You are </span>
<a name="90" /><span class="Maybe">      90:</span> <span class="k"> *    strongly encouraged to use them</span>
<a name="91" /><span class="Maybe">      91:</span> <span class="k"> *    1. Because people otherwise forget</span>
<a name="92" /><span class="Maybe">      92:</span> <span class="k"> *    2. Because if the timer wrap changes in future you won&apos;t have to</span>
<a name="93" /><span class="Maybe">      93:</span> <span class="k"> *       alter your driver code.</span>
<a name="94" /><span class="Maybe">      94:</span> <span class="k"> *</span>
<a name="95" /><span class="Maybe">      95:</span> <span class="k"> * time_after(a,b) returns true if the time a is after time b.</span>
<a name="96" /><span class="Maybe">      96:</span> <span class="k"> *</span>
<a name="97" /><span class="Maybe">      97:</span> <span class="k"> * Do this with &quot;&lt;0&quot; and &quot;&gt;=0&quot; to only test the sign of the result. A</span>
<a name="98" /><span class="Maybe">      98:</span> <span class="k"> * good compiler would generate better code (and a really good compiler</span>
<a name="99" /><span class="Maybe">      99:</span> <span class="k"> * wouldn&apos;t care). Gcc is currently neither.</span>
<a name="100" /><span class="Maybe">     100:</span> <span class="k"> */</span>
<a name="101" /><span class="Maybe">     101:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcl8w"><span class="b">time_after</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">)</span>        \
<a name="102" /><span class="Maybe">     102:</span>     <span class="f">(</span><a href="cpu.c_macros_ref.html#_dHlwZWNoZWNrXzA_"><span class="b">typecheck</span></a><span class="f">(</span><span class="m">unsigned</span> <span class="m">long</span><span class="f">,</span> <span class="b">a</span><span class="f">)</span> <span class="f">&amp;&amp;</span> \
<a name="103" /><span class="Maybe">     103:</span>      <a href="cpu.c_macros_ref.html#_dHlwZWNoZWNrXzA_"><span class="b">typecheck</span></a><span class="f">(</span><span class="m">unsigned</span> <span class="m">long</span><span class="f">,</span> <span class="b">b</span><span class="f">)</span> <span class="f">&amp;&amp;</span> \
<a name="104" /><span class="Maybe">     104:</span>      <span class="f">(</span><span class="f">(</span><span class="m">long</span><span class="f">)</span><span class="f">(</span><span class="f">(</span><span class="b">b</span><span class="f">)</span> <span class="f">-</span> <span class="f">(</span><span class="b">a</span><span class="f">)</span><span class="f">)</span> <span class="f">&lt;</span> <span class="c">0</span><span class="f">)</span><span class="f">)</span>
<a name="105" /><span class="Maybe">     105:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9iZWZvcmVfMA__"><span class="b">time_before</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">)</span>    <a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcl8w"><span class="b">time_after</span></a><span class="f">(</span><span class="b">b</span><span class="f">,</span><span class="b">a</span><span class="f">)</span>
<a name="106" /><span class="Maybe">     106:</span> 
<a name="107" /><span class="Maybe">     107:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcl9lcV8w"><span class="b">time_after_eq</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">)</span>    \
<a name="108" /><span class="Maybe">     108:</span>     <span class="f">(</span><a href="cpu.c_macros_ref.html#_dHlwZWNoZWNrXzA_"><span class="b">typecheck</span></a><span class="f">(</span><span class="m">unsigned</span> <span class="m">long</span><span class="f">,</span> <span class="b">a</span><span class="f">)</span> <span class="f">&amp;&amp;</span> \
<a name="109" /><span class="Maybe">     109:</span>      <a href="cpu.c_macros_ref.html#_dHlwZWNoZWNrXzA_"><span class="b">typecheck</span></a><span class="f">(</span><span class="m">unsigned</span> <span class="m">long</span><span class="f">,</span> <span class="b">b</span><span class="f">)</span> <span class="f">&amp;&amp;</span> \
<a name="110" /><span class="Maybe">     110:</span>      <span class="f">(</span><span class="f">(</span><span class="m">long</span><span class="f">)</span><span class="f">(</span><span class="f">(</span><span class="b">a</span><span class="f">)</span> <span class="f">-</span> <span class="f">(</span><span class="b">b</span><span class="f">)</span><span class="f">)</span> <span class="f">&gt;=</span> <span class="c">0</span><span class="f">)</span><span class="f">)</span>
<a name="111" /><span class="Maybe">     111:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9iZWZvcmVfZXFfMA__"><span class="b">time_before_eq</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">)</span>    <a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcl9lcV8w"><span class="b">time_after_eq</span></a><span class="f">(</span><span class="b">b</span><span class="f">,</span><span class="b">a</span><span class="f">)</span>
<a name="112" /><span class="Maybe">     112:</span> 
<a name="113" /><span class="Maybe">     113:</span> <span class="k">/*</span>
<a name="114" /><span class="Maybe">     114:</span> <span class="k"> * Calculate whether a is in the range of [b, c].</span>
<a name="115" /><span class="Maybe">     115:</span> <span class="k"> */</span>
<a name="116" /><span class="Maybe">     116:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9pbl9yYW5nZV8w"><span class="b">time_in_range</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">,</span><span class="b">c</span><span class="f">)</span> \
<a name="117" /><span class="Maybe">     117:</span>     <span class="f">(</span><a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcl9lcV8w"><span class="b">time_after_eq</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">)</span> <span class="f">&amp;&amp;</span> \
<a name="118" /><span class="Maybe">     118:</span>      <a href="cpu.c_macros_noref.html#_dGltZV9iZWZvcmVfZXFfMA__"><span class="b">time_before_eq</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">c</span><span class="f">)</span><span class="f">)</span>
<a name="119" /><span class="Maybe">     119:</span> 
<a name="120" /><span class="Maybe">     120:</span> <span class="k">/*</span>
<a name="121" /><span class="Maybe">     121:</span> <span class="k"> * Calculate whether a is in the range of [b, c).</span>
<a name="122" /><span class="Maybe">     122:</span> <span class="k"> */</span>
<a name="123" /><span class="Maybe">     123:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9pbl9yYW5nZV9vcGVuXzA_"><span class="b">time_in_range_open</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">,</span><span class="b">c</span><span class="f">)</span> \
<a name="124" /><span class="Maybe">     124:</span>     <span class="f">(</span><a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcl9lcV8w"><span class="b">time_after_eq</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">)</span> <span class="f">&amp;&amp;</span> \
<a name="125" /><span class="Maybe">     125:</span>      <a href="cpu.c_macros_noref.html#_dGltZV9iZWZvcmVfMA__"><span class="b">time_before</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">c</span><span class="f">)</span><span class="f">)</span>
<a name="126" /><span class="Maybe">     126:</span> 
<a name="127" /><span class="Maybe">     127:</span> <span class="k">/* Same as above, but does so with platform independent 64bit types.</span>
<a name="128" /><span class="Maybe">     128:</span> <span class="k"> * These must be used when utilizing jiffies_64 (i.e. return value of</span>
<a name="129" /><span class="Maybe">     129:</span> <span class="k"> * get_jiffies_64() */</span>
<a name="130" /><span class="Maybe">     130:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcjY0XzA_"><span class="b">time_after64</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">)</span>    \
<a name="131" /><span class="Maybe">     131:</span>     <span class="f">(</span><a href="cpu.c_macros_ref.html#_dHlwZWNoZWNrXzA_"><span class="b">typecheck</span></a><span class="f">(</span><span class="b">__u64</span><span class="f">,</span> <span class="b">a</span><span class="f">)</span> <span class="f">&amp;&amp;</span>    \
<a name="132" /><span class="Maybe">     132:</span>      <a href="cpu.c_macros_ref.html#_dHlwZWNoZWNrXzA_"><span class="b">typecheck</span></a><span class="f">(</span><span class="b">__u64</span><span class="f">,</span> <span class="b">b</span><span class="f">)</span> <span class="f">&amp;&amp;</span> \
<a name="133" /><span class="Maybe">     133:</span>      <span class="f">(</span><span class="f">(</span><span class="b">__s64</span><span class="f">)</span><span class="f">(</span><span class="f">(</span><span class="b">b</span><span class="f">)</span> <span class="f">-</span> <span class="f">(</span><span class="b">a</span><span class="f">)</span><span class="f">)</span> <span class="f">&lt;</span> <span class="c">0</span><span class="f">)</span><span class="f">)</span>
<a name="134" /><span class="Maybe">     134:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9iZWZvcmU2NF8w"><span class="b">time_before64</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">)</span>    <a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcjY0XzA_"><span class="b">time_after64</span></a><span class="f">(</span><span class="b">b</span><span class="f">,</span><span class="b">a</span><span class="f">)</span>
<a name="135" /><span class="Maybe">     135:</span> 
<a name="136" /><span class="Maybe">     136:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcl9lcTY0XzA_"><span class="b">time_after_eq64</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">)</span>    \
<a name="137" /><span class="Maybe">     137:</span>     <span class="f">(</span><a href="cpu.c_macros_ref.html#_dHlwZWNoZWNrXzA_"><span class="b">typecheck</span></a><span class="f">(</span><span class="b">__u64</span><span class="f">,</span> <span class="b">a</span><span class="f">)</span> <span class="f">&amp;&amp;</span> \
<a name="138" /><span class="Maybe">     138:</span>      <a href="cpu.c_macros_ref.html#_dHlwZWNoZWNrXzA_"><span class="b">typecheck</span></a><span class="f">(</span><span class="b">__u64</span><span class="f">,</span> <span class="b">b</span><span class="f">)</span> <span class="f">&amp;&amp;</span> \
<a name="139" /><span class="Maybe">     139:</span>      <span class="f">(</span><span class="f">(</span><span class="b">__s64</span><span class="f">)</span><span class="f">(</span><span class="f">(</span><span class="b">a</span><span class="f">)</span> <span class="f">-</span> <span class="f">(</span><span class="b">b</span><span class="f">)</span><span class="f">)</span> <span class="f">&gt;=</span> <span class="c">0</span><span class="f">)</span><span class="f">)</span>
<a name="140" /><span class="Maybe">     140:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9iZWZvcmVfZXE2NF8w"><span class="b">time_before_eq64</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span><span class="b">b</span><span class="f">)</span>    <a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcl9lcTY0XzA_"><span class="b">time_after_eq64</span></a><span class="f">(</span><span class="b">b</span><span class="f">,</span><span class="b">a</span><span class="f">)</span>
<a name="141" /><span class="Maybe">     141:</span> 
<a name="142" /><span class="Maybe">     142:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9pbl9yYW5nZTY0XzA_"><span class="b">time_in_range64</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span> <span class="b">b</span><span class="f">,</span> <span class="b">c</span><span class="f">)</span> \
<a name="143" /><span class="Maybe">     143:</span>     <span class="f">(</span><a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcl9lcTY0XzA_"><span class="b">time_after_eq64</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span> <span class="b">b</span><span class="f">)</span> <span class="f">&amp;&amp;</span> \
<a name="144" /><span class="Maybe">     144:</span>      <a href="cpu.c_macros_noref.html#_dGltZV9iZWZvcmVfZXE2NF8w"><span class="b">time_before_eq64</span></a><span class="f">(</span><span class="b">a</span><span class="f">,</span> <span class="b">c</span><span class="f">)</span><span class="f">)</span>
<a name="145" /><span class="Maybe">     145:</span> 
<a name="146" /><span class="Maybe">     146:</span> <span class="k">/*</span>
<a name="147" /><span class="Maybe">     147:</span> <span class="k"> * These four macros compare jiffies and &apos;a&apos; for convenience.</span>
<a name="148" /><span class="Maybe">     148:</span> <span class="k"> */</span>
<a name="149" /><span class="Maybe">     149:</span> 
<a name="150" /><span class="Maybe">     150:</span> <span class="k">/* time_is_before_jiffies(a) return true if a is before jiffies */</span>
<a name="151" /><span class="Maybe">     151:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9pc19iZWZvcmVfamlmZmllc18w"><span class="b">time_is_before_jiffies</span></a><span class="f">(</span><span class="b">a</span><span class="f">)</span> <a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcl8w"><span class="b">time_after</span></a><span class="f">(</span><span class="b">jiffies</span><span class="f">,</span> <span class="b">a</span><span class="f">)</span>
<a name="152" /><span class="Maybe">     152:</span> 
<a name="153" /><span class="Maybe">     153:</span> <span class="k">/* time_is_after_jiffies(a) return true if a is after jiffies */</span>
<a name="154" /><span class="Maybe">     154:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9pc19hZnRlcl9qaWZmaWVzXzA_"><span class="b">time_is_after_jiffies</span></a><span class="f">(</span><span class="b">a</span><span class="f">)</span> <a href="cpu.c_macros_noref.html#_dGltZV9iZWZvcmVfMA__"><span class="b">time_before</span></a><span class="f">(</span><span class="b">jiffies</span><span class="f">,</span> <span class="b">a</span><span class="f">)</span>
<a name="155" /><span class="Maybe">     155:</span> 
<a name="156" /><span class="Maybe">     156:</span> <span class="k">/* time_is_before_eq_jiffies(a) return true if a is before or equal to jiffies*/</span>
<a name="157" /><span class="Maybe">     157:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9pc19iZWZvcmVfZXFfamlmZmllc18w"><span class="b">time_is_before_eq_jiffies</span></a><span class="f">(</span><span class="b">a</span><span class="f">)</span> <a href="cpu.c_macros_noref.html#_dGltZV9hZnRlcl9lcV8w"><span class="b">time_after_eq</span></a><span class="f">(</span><span class="b">jiffies</span><span class="f">,</span> <span class="b">a</span><span class="f">)</span>
<a name="158" /><span class="Maybe">     158:</span> 
<a name="159" /><span class="Maybe">     159:</span> <span class="k">/* time_is_after_eq_jiffies(a) return true if a is after or equal to jiffies*/</span>
<a name="160" /><span class="Maybe">     160:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_dGltZV9pc19hZnRlcl9lcV9qaWZmaWVzXzA_"><span class="b">time_is_after_eq_jiffies</span></a><span class="f">(</span><span class="b">a</span><span class="f">)</span> <a href="cpu.c_macros_noref.html#_dGltZV9iZWZvcmVfZXFfMA__"><span class="b">time_before_eq</span></a><span class="f">(</span><span class="b">jiffies</span><span class="f">,</span> <span class="b">a</span><span class="f">)</span>
<a name="161" /><span class="Maybe">     161:</span> 
<a name="162" /><span class="Maybe">     162:</span> <span class="k">/*</span>
<a name="163" /><span class="Maybe">     163:</span> <span class="k"> * Have the 32 bit jiffies value wrap 5 minutes after boot</span>
<a name="164" /><span class="Maybe">     164:</span> <span class="k"> * so jiffies wrap bugs show up earlier.</span>
<a name="165" /><span class="Maybe">     165:</span> <span class="k"> */</span>
<a name="166" /><span class="Maybe">     166:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_SU5JVElBTF9KSUZGSUVTXzA_"><span class="b">INITIAL_JIFFIES</span></a> <span class="f">(</span><span class="f">(</span><span class="m">unsigned</span> <span class="m">long</span><span class="f">)</span><span class="f">(</span><span class="m">unsigned</span> <span class="m">int</span><span class="f">)</span> <span class="f">(</span><span class="f">-</span><span class="c">300</span><span class="f">*</span><a href="cpu.c_macros_ref.html#_SFpfMQ__"><span class="b">HZ</span></a><span class="f">)</span><span class="f">)</span>
<a name="167" /><span class="Maybe">     167:</span> 
<a name="168" /><span class="Maybe">     168:</span> <span class="k">/*</span>
<a name="169" /><span class="Maybe">     169:</span> <span class="k"> * Change timeval to jiffies, trying to avoid the</span>
<a name="170" /><span class="Maybe">     170:</span> <span class="k"> * most obvious overflows..</span>
<a name="171" /><span class="Maybe">     171:</span> <span class="k"> *</span>
<a name="172" /><span class="Maybe">     172:</span> <span class="k"> * And some not so obvious.</span>
<a name="173" /><span class="Maybe">     173:</span> <span class="k"> *</span>
<a name="174" /><span class="Maybe">     174:</span> <span class="k"> * Note that we don&apos;t want to return LONG_MAX, because</span>
<a name="175" /><span class="Maybe">     175:</span> <span class="k"> * for various timeout reasons we often end up having</span>
<a name="176" /><span class="Maybe">     176:</span> <span class="k"> * to wait &quot;jiffies+1&quot; in order to guarantee that we wait</span>
<a name="177" /><span class="Maybe">     177:</span> <span class="k"> * at _least_ &quot;jiffies&quot; - so &quot;jiffies+1&quot; had better still</span>
<a name="178" /><span class="Maybe">     178:</span> <span class="k"> * be positive.</span>
<a name="179" /><span class="Maybe">     179:</span> <span class="k"> */</span>
<a name="180" /><span class="Maybe">     180:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_TUFYX0pJRkZZX09GRlNFVF8w"><span class="b">MAX_JIFFY_OFFSET</span></a> <span class="f">(</span><span class="f">(</span><a href="cpu.c_macros_noref.html#_TE9OR19NQVhfMA__"><span class="b">LONG_MAX</span></a> <span class="f">&gt;&gt;</span> <span class="c">1</span><span class="f">)</span><span class="f">-</span><span class="c">1</span><span class="f">)</span>
<a name="181" /><span class="Maybe">     181:</span> 
<a name="182" /><span class="Maybe">     182:</span> <span class="m">extern</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">preset_lpj</span><span class="f">;</span>
<a name="183" /><span class="Maybe">     183:</span> 
<a name="184" /><span class="Maybe">     184:</span> <span class="k">/*</span>
<a name="185" /><span class="Maybe">     185:</span> <span class="k"> * We want to do realistic conversions of time so we need to use the same</span>
<a name="186" /><span class="Maybe">     186:</span> <span class="k"> * values the update wall clock code uses as the jiffies size.  This value</span>
<a name="187" /><span class="Maybe">     187:</span> <span class="k"> * is: TICK_NSEC (which is defined in timex.h).  This</span>
<a name="188" /><span class="Maybe">     188:</span> <span class="k"> * is a constant and is in nanoseconds.  We will use scaled math</span>
<a name="189" /><span class="Maybe">     189:</span> <span class="k"> * with a set of scales defined here as SEC_JIFFIE_SC,  USEC_JIFFIE_SC and</span>
<a name="190" /><span class="Maybe">     190:</span> <span class="k"> * NSEC_JIFFIE_SC.  Note that these defines contain nothing but</span>
<a name="191" /><span class="Maybe">     191:</span> <span class="k"> * constants and so are computed at compile time.  SHIFT_HZ (computed in</span>
<a name="192" /><span class="Maybe">     192:</span> <span class="k"> * timex.h) adjusts the scaling for different HZ values.</span>
<a name="193" /><span class="Maybe">     193:</span> <span class="k"></span>
<a name="194" /><span class="Maybe">     194:</span> <span class="k"> * Scaled math???  What is that?</span>
<a name="195" /><span class="Maybe">     195:</span> <span class="k"> *</span>
<a name="196" /><span class="Maybe">     196:</span> <span class="k"> * Scaled math is a way to do integer math on values that would,</span>
<a name="197" /><span class="Maybe">     197:</span> <span class="k"> * otherwise, either overflow, underflow, or cause undesired div</span>
<a name="198" /><span class="Maybe">     198:</span> <span class="k"> * instructions to appear in the execution path.  In short, we &quot;scale&quot;</span>
<a name="199" /><span class="Maybe">     199:</span> <span class="k"> * up the operands so they take more bits (more precision, less</span>
<a name="200" /><span class="Maybe">     200:</span> <span class="k"> * underflow), do the desired operation and then &quot;scale&quot; the result back</span>
<a name="201" /><span class="Maybe">     201:</span> <span class="k"> * by the same amount.  If we do the scaling by shifting we avoid the</span>
<a name="202" /><span class="Maybe">     202:</span> <span class="k"> * costly mpy and the dastardly div instructions.</span>
<a name="203" /><span class="Maybe">     203:</span> <span class="k"></span>
<a name="204" /><span class="Maybe">     204:</span> <span class="k"> * Suppose, for example, we want to convert from seconds to jiffies</span>
<a name="205" /><span class="Maybe">     205:</span> <span class="k"> * where jiffies is defined in nanoseconds as NSEC_PER_JIFFIE.  The</span>
<a name="206" /><span class="Maybe">     206:</span> <span class="k"> * simple math is: jiff = (sec * NSEC_PER_SEC) / NSEC_PER_JIFFIE; We</span>
<a name="207" /><span class="Maybe">     207:</span> <span class="k"> * observe that (NSEC_PER_SEC / NSEC_PER_JIFFIE) is a constant which we</span>
<a name="208" /><span class="Maybe">     208:</span> <span class="k"> * might calculate at compile time, however, the result will only have</span>
<a name="209" /><span class="Maybe">     209:</span> <span class="k"> * about 3-4 bits of precision (less for smaller values of HZ).</span>
<a name="210" /><span class="Maybe">     210:</span> <span class="k"> *</span>
<a name="211" /><span class="Maybe">     211:</span> <span class="k"> * So, we scale as follows:</span>
<a name="212" /><span class="Maybe">     212:</span> <span class="k"> * jiff = (sec) * (NSEC_PER_SEC / NSEC_PER_JIFFIE);</span>
<a name="213" /><span class="Maybe">     213:</span> <span class="k"> * jiff = ((sec) * ((NSEC_PER_SEC * SCALE)/ NSEC_PER_JIFFIE)) / SCALE;</span>
<a name="214" /><span class="Maybe">     214:</span> <span class="k"> * Then we make SCALE a power of two so:</span>
<a name="215" /><span class="Maybe">     215:</span> <span class="k"> * jiff = ((sec) * ((NSEC_PER_SEC &lt;&lt; SCALE)/ NSEC_PER_JIFFIE)) &gt;&gt; SCALE;</span>
<a name="216" /><span class="Maybe">     216:</span> <span class="k"> * Now we define:</span>
<a name="217" /><span class="Maybe">     217:</span> <span class="k"> * #define SEC_CONV = ((NSEC_PER_SEC &lt;&lt; SCALE)/ NSEC_PER_JIFFIE))</span>
<a name="218" /><span class="Maybe">     218:</span> <span class="k"> * jiff = (sec * SEC_CONV) &gt;&gt; SCALE;</span>
<a name="219" /><span class="Maybe">     219:</span> <span class="k"> *</span>
<a name="220" /><span class="Maybe">     220:</span> <span class="k"> * Often the math we use will expand beyond 32-bits so we tell C how to</span>
<a name="221" /><span class="Maybe">     221:</span> <span class="k"> * do this and pass the 64-bit result of the mpy through the &quot;&gt;&gt; SCALE&quot;</span>
<a name="222" /><span class="Maybe">     222:</span> <span class="k"> * which should take the result back to 32-bits.  We want this expansion</span>
<a name="223" /><span class="Maybe">     223:</span> <span class="k"> * to capture as much precision as possible.  At the same time we don&apos;t</span>
<a name="224" /><span class="Maybe">     224:</span> <span class="k"> * want to overflow so we pick the SCALE to avoid this.  In this file,</span>
<a name="225" /><span class="Maybe">     225:</span> <span class="k"> * that means using a different scale for each range of HZ values (as</span>
<a name="226" /><span class="Maybe">     226:</span> <span class="k"> * defined in timex.h).</span>
<a name="227" /><span class="Maybe">     227:</span> <span class="k"> *</span>
<a name="228" /><span class="Maybe">     228:</span> <span class="k"> * For those who want to know, gcc will give a 64-bit result from a &quot;*&quot;</span>
<a name="229" /><span class="Maybe">     229:</span> <span class="k"> * operator if the result is a long long AND at least one of the</span>
<a name="230" /><span class="Maybe">     230:</span> <span class="k"> * operands is cast to long long (usually just prior to the &quot;*&quot; so as</span>
<a name="231" /><span class="Maybe">     231:</span> <span class="k"> * not to confuse it into thinking it really has a 64-bit operand,</span>
<a name="232" /><span class="Maybe">     232:</span> <span class="k"> * which, buy the way, it can do, but it takes more code and at least 2</span>
<a name="233" /><span class="Maybe">     233:</span> <span class="k"> * mpys).</span>
<a name="234" /><span class="Maybe">     234:</span> <span class="k"></span>
<a name="235" /><span class="Maybe">     235:</span> <span class="k"> * We also need to be aware that one second in nanoseconds is only a</span>
<a name="236" /><span class="Maybe">     236:</span> <span class="k"> * couple of bits away from overflowing a 32-bit word, so we MUST use</span>
<a name="237" /><span class="Maybe">     237:</span> <span class="k"> * 64-bits to get the full range time in nanoseconds.</span>
<a name="238" /><span class="Maybe">     238:</span> <span class="k"></span>
<a name="239" /><span class="Maybe">     239:</span> <span class="k"> */</span>
<a name="240" /><span class="Maybe">     240:</span> 
<a name="241" /><span class="Maybe">     241:</span> <span class="k">/*</span>
<a name="242" /><span class="Maybe">     242:</span> <span class="k"> * Here are the scales we will use.  One for seconds, nanoseconds and</span>
<a name="243" /><span class="Maybe">     243:</span> <span class="k"> * microseconds.</span>
<a name="244" /><span class="Maybe">     244:</span> <span class="k"> *</span>
<a name="245" /><span class="Maybe">     245:</span> <span class="k"> * Within the limits of cpp we do a rough cut at the SEC_JIFFIE_SC and</span>
<a name="246" /><span class="Maybe">     246:</span> <span class="k"> * check if the sign bit is set.  If not, we bump the shift count by 1.</span>
<a name="247" /><span class="Maybe">     247:</span> <span class="k"> * (Gets an extra bit of precision where we can use it.)</span>
<a name="248" /><span class="Maybe">     248:</span> <span class="k"> * We know it is set for HZ = 1024 and HZ = 100 not for 1000.</span>
<a name="249" /><span class="Maybe">     249:</span> <span class="k"> * Haven&apos;t tested others.</span>
<a name="250" /><span class="Maybe">     250:</span> <span class="k"></span>
<a name="251" /><span class="Maybe">     251:</span> <span class="k"> * Limits of cpp (for #if expressions) only long (no long long), but</span>
<a name="252" /><span class="Maybe">     252:</span> <span class="k"> * then we only need the most signicant bit.</span>
<a name="253" /><span class="Maybe">     253:</span> <span class="k"> */</span>
<a name="254" /><span class="Maybe">     254:</span> 
<a name="255" /><span class="Maybe">     255:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0VDX0pJRkZJRV9TQ18w"><span class="b">SEC_JIFFIE_SC</span></a> <span class="f">(</span><span class="c">31</span> <span class="f">-</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a><span class="f">)</span>
<a name="256" /><span class="False">     256:</span> <span class="f">#</span><span class="n">if</span> <span class="f">!</span><span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="f">(</span><a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfU0VDXzA_"><span class="b">NSEC_PER_SEC</span></a> <span class="f">&lt;&lt;</span> <span class="c">2</span><span class="f">)</span> <span class="f">/</span> <a href="cpu.c_macros_ref.html#_VElDS19OU0VDXzA_"><span class="b">TICK_NSEC</span></a><span class="f">)</span> <span class="f">&lt;&lt;</span> <span class="f">(</span><a href="cpu.c_macros_ref.html#_U0VDX0pJRkZJRV9TQ18w"><span class="b">SEC_JIFFIE_SC</span></a> <span class="f">-</span> <span class="c">2</span><span class="f">)</span><span class="f">)</span> <span class="f">&amp;</span> <span class="c">0x80000000</span><span class="f">)</span>
<a name="257" /><span class="False">     257:</span> <span class="f">#</span><span class="n">undef</span> <a href="cpu.c_macros_ref.html#_U0VDX0pJRkZJRV9TQ18w"><span class="b">SEC_JIFFIE_SC</span></a>
<a name="258" /><span class="False">     258:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_ref.html#_U0VDX0pJRkZJRV9TQ18w"><span class="b">SEC_JIFFIE_SC</span></a> <span class="f">(</span><span class="c">32</span> <span class="f">-</span> <a href="cpu.c_macros_ref.html#_U0hJRlRfSFpfMA__"><span class="b">SHIFT_HZ</span></a><span class="f">)</span>
<a name="259" /><span class="Maybe">     259:</span> <span class="f">#</span><span class="n">endif</span>
<a name="260" /><span class="Maybe">     260:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_TlNFQ19KSUZGSUVfU0NfMA__"><span class="b">NSEC_JIFFIE_SC</span></a> <span class="f">(</span><a href="cpu.c_macros_ref.html#_U0VDX0pJRkZJRV9TQ18w"><span class="b">SEC_JIFFIE_SC</span></a> <span class="f">+</span> <span class="c">29</span><span class="f">)</span>
<a name="261" /><span class="Maybe">     261:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_VVNFQ19KSUZGSUVfU0NfMA__"><span class="b">USEC_JIFFIE_SC</span></a> <span class="f">(</span><a href="cpu.c_macros_ref.html#_U0VDX0pJRkZJRV9TQ18w"><span class="b">SEC_JIFFIE_SC</span></a> <span class="f">+</span> <span class="c">19</span><span class="f">)</span>
<a name="262" /><span class="Maybe">     262:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_U0VDX0NPTlZFUlNJT05fMA__"><span class="b">SEC_CONVERSION</span></a> <span class="f">(</span><span class="f">(</span><span class="m">unsigned</span> <span class="m">long</span><span class="f">)</span><span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="b">u64</span><span class="f">)</span><a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfU0VDXzA_"><span class="b">NSEC_PER_SEC</span></a> <span class="f">&lt;&lt;</span> <a href="cpu.c_macros_ref.html#_U0VDX0pJRkZJRV9TQ18w"><span class="b">SEC_JIFFIE_SC</span></a><span class="f">)</span> <span class="f">+\
</span>                                <a href="cpu.c_macros_ref.html#_VElDS19OU0VDXzA_"><span class="b">TICK_NSEC</span></a> <span class="f">-</span><span class="c">1</span><span class="f">)</span> <span class="f">/</span> <span class="f">(</span><span class="b">u64</span><span class="f">)</span><a href="cpu.c_macros_ref.html#_VElDS19OU0VDXzA_"><span class="b">TICK_NSEC</span></a><span class="f">)</span><span class="f">)</span>
<a name="264" /><span class="Maybe">     264:</span> 
<a name="265" /><span class="Maybe">     265:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_TlNFQ19DT05WRVJTSU9OXzA_"><span class="b">NSEC_CONVERSION</span></a> <span class="f">(</span><span class="f">(</span><span class="m">unsigned</span> <span class="m">long</span><span class="f">)</span><span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="b">u64</span><span class="f">)</span><span class="c">1</span> <span class="f">&lt;&lt;</span> <a href="cpu.c_macros_noref.html#_TlNFQ19KSUZGSUVfU0NfMA__"><span class="b">NSEC_JIFFIE_SC</span></a><span class="f">)</span> <span class="f">+\
</span>                                        <a href="cpu.c_macros_ref.html#_VElDS19OU0VDXzA_"><span class="b">TICK_NSEC</span></a> <span class="f">-</span><span class="c">1</span><span class="f">)</span> <span class="f">/</span> <span class="f">(</span><span class="b">u64</span><span class="f">)</span><a href="cpu.c_macros_ref.html#_VElDS19OU0VDXzA_"><span class="b">TICK_NSEC</span></a><span class="f">)</span><span class="f">)</span>
<a name="267" /><span class="Maybe">     267:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_VVNFQ19DT05WRVJTSU9OXzA_"><span class="b">USEC_CONVERSION</span></a>  \
<a name="268" /><span class="Maybe">     268:</span>                     <span class="f">(</span><span class="f">(</span><span class="m">unsigned</span> <span class="m">long</span><span class="f">)</span><span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="b">u64</span><span class="f">)</span><a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfVVNFQ18w"><span class="b">NSEC_PER_USEC</span></a> <span class="f">&lt;&lt;</span> <a href="cpu.c_macros_noref.html#_VVNFQ19KSUZGSUVfU0NfMA__"><span class="b">USEC_JIFFIE_SC</span></a><span class="f">)</span> <span class="f">+\
</span>                                        <a href="cpu.c_macros_ref.html#_VElDS19OU0VDXzA_"><span class="b">TICK_NSEC</span></a> <span class="f">-</span><span class="c">1</span><span class="f">)</span> <span class="f">/</span> <span class="f">(</span><span class="b">u64</span><span class="f">)</span><a href="cpu.c_macros_ref.html#_VElDS19OU0VDXzA_"><span class="b">TICK_NSEC</span></a><span class="f">)</span><span class="f">)</span>
<a name="270" /><span class="Maybe">     270:</span> <span class="k">/*</span>
<a name="271" /><span class="Maybe">     271:</span> <span class="k"> * USEC_ROUND is used in the timeval to jiffie conversion.  See there</span>
<a name="272" /><span class="Maybe">     272:</span> <span class="k"> * for more details.  It is the scaled resolution rounding value.  Note</span>
<a name="273" /><span class="Maybe">     273:</span> <span class="k"> * that it is a 64-bit value.  Since, when it is applied, we are already</span>
<a name="274" /><span class="Maybe">     274:</span> <span class="k"> * in jiffies (albit scaled), it is nothing but the bits we will shift</span>
<a name="275" /><span class="Maybe">     275:</span> <span class="k"> * off.</span>
<a name="276" /><span class="Maybe">     276:</span> <span class="k"> */</span>
<a name="277" /><span class="Maybe">     277:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_VVNFQ19ST1VORF8w"><span class="b">USEC_ROUND</span></a> <span class="f">(</span><span class="b">u64</span><span class="f">)</span><span class="f">(</span><span class="f">(</span><span class="f">(</span><span class="b">u64</span><span class="f">)</span><span class="c">1</span> <span class="f">&lt;&lt;</span> <a href="cpu.c_macros_noref.html#_VVNFQ19KSUZGSUVfU0NfMA__"><span class="b">USEC_JIFFIE_SC</span></a><span class="f">)</span> <span class="f">-</span> <span class="c">1</span><span class="f">)</span>
<a name="278" /><span class="Maybe">     278:</span> <span class="k">/*</span>
<a name="279" /><span class="Maybe">     279:</span> <span class="k"> * The maximum jiffie value is (MAX_INT &gt;&gt; 1).  Here we translate that</span>
<a name="280" /><span class="Maybe">     280:</span> <span class="k"> * into seconds.  The 64-bit case will overflow if we are not careful,</span>
<a name="281" /><span class="Maybe">     281:</span> <span class="k"> * so use the messy SH_DIV macro to do it.  Still all constants.</span>
<a name="282" /><span class="Maybe">     282:</span> <span class="k"> */</span>
<a name="283" /><span class="False">     283:</span> <span class="f">#</span><span class="n">if</span> <a href="cpu.c_macros_ref.html#_QklUU19QRVJfTE9OR18w"><span class="b">BITS_PER_LONG</span></a> <span class="f">&lt;</span> <span class="c">64</span>
<a name="284" /><span class="False">     284:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_noref.html#_TUFYX1NFQ19JTl9KSUZGSUVTXzA_"><span class="b">MAX_SEC_IN_JIFFIES</span></a> \
<a name="285" /><span class="False">     285:</span>     <span class="f">(</span><span class="m">long</span><span class="f">)</span><span class="f">(</span><span class="f">(</span><span class="b">u64</span><span class="f">)</span><span class="f">(</span><span class="f">(</span><span class="b">u64</span><span class="f">)</span><a href="cpu.c_macros_noref.html#_TUFYX0pJRkZZX09GRlNFVF8w"><span class="b">MAX_JIFFY_OFFSET</span></a> <span class="f">*</span> <a href="cpu.c_macros_ref.html#_VElDS19OU0VDXzA_"><span class="b">TICK_NSEC</span></a><span class="f">)</span> <span class="f">/</span> <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfU0VDXzA_"><span class="b">NSEC_PER_SEC</span></a><span class="f">)</span>
<a name="286" /><span class="Maybe">     286:</span> <span class="f">#</span><span class="n">else</span>    <span class="k">/* take care of overflow on 64 bits machines */</span>
<a name="287" /><span class="Maybe">     287:</span> <span class="f">#</span> <span class="n">define</span> <a href="cpu.c_macros_noref.html#_TUFYX1NFQ19JTl9KSUZGSUVTXzA_"><span class="b">MAX_SEC_IN_JIFFIES</span></a> \
<a name="288" /><span class="Maybe">     288:</span>     <span class="f">(</span><a href="cpu.c_macros_noref.html#_U0hfRElWXzA_"><span class="b">SH_DIV</span></a><span class="f">(</span><span class="f">(</span><a href="cpu.c_macros_noref.html#_TUFYX0pJRkZZX09GRlNFVF8w"><span class="b">MAX_JIFFY_OFFSET</span></a> <span class="f">&gt;&gt;</span> <a href="cpu.c_macros_ref.html#_U0VDX0pJRkZJRV9TQ18w"><span class="b">SEC_JIFFIE_SC</span></a><span class="f">)</span> <span class="f">*</span> <a href="cpu.c_macros_ref.html#_VElDS19OU0VDXzA_"><span class="b">TICK_NSEC</span></a><span class="f">,</span> <a href="cpu.c_macros_ref.html#_TlNFQ19QRVJfU0VDXzA_"><span class="b">NSEC_PER_SEC</span></a><span class="f">,</span> <span class="c">1</span><span class="f">)</span> <span class="f">-</span> <span class="c">1</span><span class="f">)</span>
<a name="289" /><span class="Maybe">     289:</span> 
<a name="290" /><span class="Maybe">     290:</span> <span class="f">#</span><span class="n">endif</span>
<a name="291" /><span class="Maybe">     291:</span> 
<a name="292" /><span class="Maybe">     292:</span> <span class="k">/*</span>
<a name="293" /><span class="Maybe">     293:</span> <span class="k"> * Convert various time units to each other:</span>
<a name="294" /><span class="Maybe">     294:</span> <span class="k"> */</span>
<a name="295" /><span class="Maybe">     295:</span> <span class="m">extern</span> <span class="m">unsigned</span> <span class="m">int</span> <span class="b">jiffies_to_msecs</span><span class="f">(</span><span class="m">const</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">j</span><span class="f">)</span><span class="f">;</span>
<a name="296" /><span class="Maybe">     296:</span> <span class="m">extern</span> <span class="m">unsigned</span> <span class="m">int</span> <span class="b">jiffies_to_usecs</span><span class="f">(</span><span class="m">const</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">j</span><span class="f">)</span><span class="f">;</span>
<a name="297" /><span class="Maybe">     297:</span> <span class="m">extern</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">msecs_to_jiffies</span><span class="f">(</span><span class="m">const</span> <span class="m">unsigned</span> <span class="m">int</span> <span class="b">m</span><span class="f">)</span><span class="f">;</span>
<a name="298" /><span class="Maybe">     298:</span> <span class="m">extern</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">usecs_to_jiffies</span><span class="f">(</span><span class="m">const</span> <span class="m">unsigned</span> <span class="m">int</span> <span class="b">u</span><span class="f">)</span><span class="f">;</span>
<a name="299" /><span class="Maybe">     299:</span> <span class="m">extern</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">timespec_to_jiffies</span><span class="f">(</span><span class="m">const</span> <span class="m">struct</span> <span class="b">timespec</span> <span class="f">*</span><span class="b">value</span><span class="f">)</span><span class="f">;</span>
<a name="300" /><span class="Maybe">     300:</span> <span class="m">extern</span> <span class="m">void</span> <span class="b">jiffies_to_timespec</span><span class="f">(</span><span class="m">const</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">jiffies</span><span class="f">,</span>
<a name="301" /><span class="Maybe">     301:</span>                 <span class="m">struct</span> <span class="b">timespec</span> <span class="f">*</span><span class="b">value</span><span class="f">)</span><span class="f">;</span>
<a name="302" /><span class="Maybe">     302:</span> <span class="m">extern</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">timeval_to_jiffies</span><span class="f">(</span><span class="m">const</span> <span class="m">struct</span> <span class="b">timeval</span> <span class="f">*</span><span class="b">value</span><span class="f">)</span><span class="f">;</span>
<a name="303" /><span class="Maybe">     303:</span> <span class="m">extern</span> <span class="m">void</span> <span class="b">jiffies_to_timeval</span><span class="f">(</span><span class="m">const</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">jiffies</span><span class="f">,</span>
<a name="304" /><span class="Maybe">     304:</span>                    <span class="m">struct</span> <span class="b">timeval</span> <span class="f">*</span><span class="b">value</span><span class="f">)</span><span class="f">;</span>
<a name="305" /><span class="Maybe">     305:</span> 
<a name="306" /><span class="Maybe">     306:</span> <span class="m">extern</span> <span class="b">clock_t</span> <span class="b">jiffies_to_clock_t</span><span class="f">(</span><span class="m">unsigned</span> <span class="m">long</span> <span class="b">x</span><span class="f">)</span><span class="f">;</span>
<a name="307" /><span class="Maybe">     307:</span> <span class="m">static</span> <span class="m">inline</span> <span class="b">clock_t</span> <span class="b">jiffies_delta_to_clock_t</span><span class="f">(</span><span class="m">long</span> <span class="b">delta</span><span class="f">)</span>
<a name="308" /><span class="Maybe">     308:</span> <span class="f">{</span>
<a name="309" /><span class="Maybe">     309:</span>     <span class="m">return</span> <span class="b">jiffies_to_clock_t</span><span class="f">(</span><a href="cpu.c_macros_ref.html#_bWF4XzA_"><span class="b">max</span></a><span class="f">(</span><span class="c">0L</span><span class="f">,</span> <span class="b">delta</span><span class="f">)</span><span class="f">)</span><span class="f">;</span>
<a name="310" /><span class="Maybe">     310:</span> <span class="f">}</span>
<a name="311" /><span class="Maybe">     311:</span> 
<a name="312" /><span class="Maybe">     312:</span> <span class="m">extern</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">clock_t_to_jiffies</span><span class="f">(</span><span class="m">unsigned</span> <span class="m">long</span> <span class="b">x</span><span class="f">)</span><span class="f">;</span>
<a name="313" /><span class="Maybe">     313:</span> <span class="m">extern</span> <span class="b">u64</span> <span class="b">jiffies_64_to_clock_t</span><span class="f">(</span><span class="b">u64</span> <span class="b">x</span><span class="f">)</span><span class="f">;</span>
<a name="314" /><span class="Maybe">     314:</span> <span class="m">extern</span> <span class="b">u64</span> <span class="b">nsec_to_clock_t</span><span class="f">(</span><span class="b">u64</span> <span class="b">x</span><span class="f">)</span><span class="f">;</span>
<a name="315" /><span class="Maybe">     315:</span> <span class="m">extern</span> <span class="b">u64</span> <span class="b">nsecs_to_jiffies64</span><span class="f">(</span><span class="b">u64</span> <span class="b">n</span><span class="f">)</span><span class="f">;</span>
<a name="316" /><span class="Maybe">     316:</span> <span class="m">extern</span> <span class="m">unsigned</span> <span class="m">long</span> <span class="b">nsecs_to_jiffies</span><span class="f">(</span><span class="b">u64</span> <span class="b">n</span><span class="f">)</span><span class="f">;</span>
<a name="317" /><span class="Maybe">     317:</span> 
<a name="318" /><span class="Maybe">     318:</span> <span class="f">#</span><span class="n">define</span> <a href="cpu.c_macros_noref.html#_VElNRVNUQU1QX1NJWkVfMA__"><span class="b">TIMESTAMP_SIZE</span></a>    <span class="c">30</span>
<a name="319" /><span class="Maybe">     319:</span> 
<a name="320" /><span class="True">     320:</span> <span class="f">#</span><span class="n">endif</span>
<a name="321" /><span class="True">     321:</span> </pre>
  </body>
</html>
